package com.woniu.lifeservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.lifeservice.pojo.ServiceDetails;
import com.woniu.lifeservice.mapper.ServiceDetailsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.lifeservice.service.IServiceDetailsService;
import com.woniu.lifeservice.vo.ServiceDetailsVO;
import com.woniu.user.vo.UserLoginVO;
import com.woniu.user.vo.UserMessageVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务详情表 服务实现类
 * </p>
 *
 * @author hushunlai
 * @since 2023-05-22
 */
@Service
public class ServiceDetailsServiceImpl extends ServiceImpl<ServiceDetailsMapper, ServiceDetails> implements IServiceDetailsService {
    @Resource
    private ServiceDetailsMapper serviceDetailsMapper;

    @Override
    public List<ServiceDetailsVO> listSearch(String serviceTitle) {
        List<ServiceDetailsVO> serviceDetailsList = serviceDetailsMapper.listSearch(serviceTitle);
        return serviceDetailsList;
    }

    @Override
    public List<ServiceDetailsVO> nameSearch(String userName) {
        List<ServiceDetailsVO> serviceDetailsList = serviceDetailsMapper.nameSearch(userName);
        return serviceDetailsList;
    }

    @Override
    public List<ServiceDetailsVO> visitorRank() {
        List<ServiceDetailsVO> serviceDetailsList = serviceDetailsMapper.visitorRank();
        return serviceDetailsList;
    }

    @Override
    public List<ServiceDetails> detailsPage(Integer serviceId) {
        List<ServiceDetails> serviceDetailsList = serviceDetailsMapper.detailsPage(serviceId);
        return serviceDetailsList;
    }

    @Override
    public List<ServiceDetailsVO> latestPosting() {
        List<ServiceDetailsVO> serviceDetailsList = serviceDetailsMapper.latestPosting();
        return serviceDetailsList;
    }

    @Override
    public ServiceDetails add(ServiceDetails serviceDetails, UserLoginVO userLoginVO) {
        ServiceDetails service = new ServiceDetails();
        service.setUserId(userLoginVO.getId());
        service.setAddress(serviceDetails.getAddress());
        service.setServiceTitle(serviceDetails.getServiceTitle());
        service.setServiceCategoryFirst(serviceDetails.getServiceCategoryFirst());
        service.setServiceCategorySecond(serviceDetails.getServiceCategorySecond());
        service.setServiceDetails(serviceDetails.getServiceDetails());
        service.setDetailsPhoto(serviceDetails.getDetailsPhoto());
        service.setVisit(serviceDetails.getVisit());
        service.setPublishType(serviceDetails.getPublishType());
        service.setMobil(serviceDetails.getMobil());
        service.setVisitors(serviceDetails.getVisitors());
        serviceDetailsMapper.insert(service);
        return service;
    }

    @Override
    public List<ServiceDetailsVO> recommend() {
        List<ServiceDetailsVO> serviceDetailsList = serviceDetailsMapper.recommend();
        return serviceDetailsList;
    }

    @Override
    public List<UserMessageVO> userMessage(Integer userId) {
        List<UserMessageVO> userMessageVOList = serviceDetailsMapper.userMessage();
        return userMessageVOList;
    }

    @Override
    public List<ServiceDetailsVO> categorySearch(String service_category_second) {
        List<ServiceDetailsVO> serviceDetailsVOList = serviceDetailsMapper.categorySearch(service_category_second);
        return serviceDetailsVOList;
    }

    private Boolean isStore(UserLoginVO userLoginVO) {
        if (userLoginVO.getStoreId() == null) {
            return false;
        }
        return true;
    }
}
